#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdlib.h>
#include<vector>

using namespace std;



class Bloomfilter
{
public:
	Bloomfilter(int bitesize=1471)
		:bitesize_(bitesize)
	{
		bitemap.resize(bitesize_ / 32 + 1);
	}
public:
	//添加元素
	void set(const char* str)
	{
		//通过k个哈希函数来计算相应的值
		int idx1 = BKDRHash(str) % bitesize_;
		int idx2 = RSHash(str) % bitesize_;
		int idx3 = APHash(str) % bitesize_;
		int index = 0;
		int offset = 0;
		index = idx1 / 32;
		offset = idx1 % 32;
		bitemap[index] |= (1 << offset);
		index = idx2 / 32;
		offset = idx2 % 32;
		bitemap[index] |= (1 << offset);
		index = idx3 / 32;
		offset = idx3 % 32;
		bitemap[index] |= (1 << offset);
	}
	//查询元素
	bool get(const char* str)
	{
		int idx1 = BKDRHash(str) % bitesize_;
		int idx2 = RSHash(str) % bitesize_;
		int idx3 = APHash(str) % bitesize_;
		int index = 0;
		int offset = 0;
		index = idx1 / 32;
		offset = idx1 % 32;
		if (0 == bitemap[index] & (1 << offset))
		{
			return false;
		}
		index = idx2 / 32;
		offset = idx2 % 32;
		if (0 == bitemap[index] & (1 << offset))
		{
			return false;
		}
		index = idx3 / 32;
		offset = idx3 % 32;
		if (0 == bitemap[index] & (1 << offset))
		{
			return false;
		}
		return true;
	}
private:
	int bitesize_;
	vector<int> bitemap;




};
class Blacklist
{
public:
	void add(string url)
	{
		blocklist.set(url.c_str());
	}
	bool query(string url)
	{
		return blocklist.get(url.c_str());
	}


private:
	Bloomfilter blocklist;
};

int main()
{
	Blacklist list;
	list.add("https://www.baidu.com");
	list.add("https://www.huawei.com");
	list.add("https://www.tencent.com");
	list.add("https://www.tmall.com");
	string url = "https://www.alibaba.com";

	cout << list.query(url) << endl;
	return 0;
}